import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

import {getYi,postArticleList,
    postArticleListMain,
    postSearch,postSearchTrue,
    postDetail,
    postClickAdd,
    getNewComments,
    postComment
    } from '@/api'

const state = {}

const actions = {
    async reqGetYI (){
        let result = await getYi();
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //获取文章列表 分类 页码 排序方式
    async reqArticleList (context,obj){
        let {one_source,page,sort} = obj
        let result = await postArticleList(one_source,page,sort);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //总查询
    async reqSearchAll (context,obj){
        let {time,page,tags,sort,way,title} = obj
        let result = await postArticleListMain(time,page,tags,sort,way,title);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //搜索查询
    async reqSearch (context,queryString){
        let result = await postSearch(queryString);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //真搜索查询
    async reqSearchTrue (context,item){
        let result = await postSearchTrue(item);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //单独文章 包括评论
    async reqDetail(context,article_id){
        let result = await postDetail(article_id)
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //点击量增加
    reqClickAdd(context,article_id){
        postClickAdd(article_id);
    },
    //最新评论获取
    async reqNewComments(context){
        let result = await getNewComments()
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //拿到所有评论
    async reqComment(context,article_id){
        let result = await postComment(article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
}

const mutations = {}

const getters = {}

export default {
    namespaced:true,state,mutations,actions,getters
}